<template>
  <div class="container" ref="mainCon">
    <topTitle
      titleText="日志列表"
      :back="true"
      @gobackTriser="goBack"
    ></topTitle>
    <div class="mainCon">
      <el-row class="searchBox searchInputWidth">
        <el-form :inline="true" :model="filterField" ref="accountForm">
          <el-col :lg="8" :xl="6">
            <el-form-item label="文件模式" class="row-padding-bottom">
              <el-select
                v-model="filterField.fileType"
                placeholder="请选择"
                clearable
              >
                <el-option
                  v-for="item of typeOptions"
                  :key="item.code"
                  :label="item.name"
                  :value="item.code"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :lg="10" :xl="7">
            <el-form-item label="创建时间" class="row-padding-bottom">
              <timeSelection
                @getStartTimeValue="getStartTimeValue"
                @getEndTimeValue="getEndTimeValue"
              ></timeSelection>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :xl="6">
            <el-form-item label="">
              <el-button
                type="primary"
                icon="icon iconfont iconchazhao1"
                @click="searchTable"
                class="searchBtn"
              >
                <span>搜索</span>
              </el-button>
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <div class="spacing"></div>
      <div
        ref="tableBox"
        :class="hiddleToolBar ? 'tableBoxCur tableBox' : 'tableBoxCur'"
      >
        <!-- 列表 -->
        <el-table
          :data="tableData"
          ref="tableBox1"
          :max-height="tableHeight"
          :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
          highlight-current-row
          stripe
          v-loading="loading"
          style="border: 1px solid #dfe6ec"
        >
          <el-table-column label="项目SN" width="230">
            <template slot-scope="scope">
              <copyText
                :tableIndex="scope.$index"
                :copyTextName="scope.row.machineNo"
                :columnName="'machineNo'"
              ></copyText>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="fileTypeDesc"
            label="文件模式"
            width="200"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="ip"
            label="设备IP地址"
            width="230"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="createTime"
            label="日志上传时间"
            :formatter="formatTd"
            width="280"
          />
          <el-table-column label="日志文件" width="230">
            <template slot-scope="scope">
              <el-link
                v-if="scope.row.fileType === 'FILESTREAM'"
                type="primary"
                @click="download(scope.row)"
                >下载日志</el-link
              >
              <copyText
                v-else
                :tableIndex="scope.$index"
                :copyTextName="scope.row.url"
                :columnName="'url'"
              ></copyText>
            </template>
          </el-table-column>
          <!-- 表格数据为空时，页面显示 -->
          <div slot="empty" v-show="isShow">
            <emptyTable emptyText="暂无相关信息"></emptyTable>
          </div>
        </el-table>
        <!-- filterField为搜索条件 -->
        <Pagination
          ref="pagination"
          @getList="getTableList"
          :filterField="filterField"
          :requestUrl="requestUrl"
          @getpageSize="getpageSize"
          @getpageNo="getpageNo"
        ></Pagination>
      </div>
    </div>
  </div>
</template>

<script>
import scrollTable from '@/mixin/scrollTable.js'
import common from '@/kits/common'
export default {
  name: 'journalList',
  mixins: [scrollTable],
  data() {
    return {
      requestUrl: 'api-att/cs/macMachineLog/expand/list',
      advanced: false,
      loading: false,
      isShow: false,
      typeOptions: [],
      tableData: [], //表格数据
      filterField: {
        fileType: '', //文件模式
        machineNo: '', //设备识别号
        startDateStr: '', //开始时间
        endDateStr: '', //结束时间
      },
      pageSize: 20,
      pageNo: 1,
      isShowDetail: '',
    }
  },
  created() {
    this.getType()
    this.filterField.machineNo = this.$route.query.machineNo
  },
  mounted() {
    this.$nextTick(function () {
      this.$refs.pagination.getTableListData()
    })
  },
  activated() {
    this.$nextTick(function () {
      this.$refs.pagination.getTableListData(this.pageNo, this.pageSize)
    })
  },
  methods: {
    toggleAdvanced() {
      this.advanced = !this.advanced
    },
    getpageSize(val) {
      this.pageSize = val
    },
    getpageNo(val) {
      this.pageNo = val
    },
    goBack() {
      this.$router.push({
        name: 'equipmentMonitor',
        path: '/home/operationManage/equipmentMonitor',
      })
      this.$store.commit('GOBACK_NAME', {
        oldUrl: '/home/operationManage/equipmentMonitor',
        newUrl: this.$router.currentRoute.fullPath,
      })
    },
    // 列表筛选
    getStartTimeValue(val) {
      if (val) {
        this.filterField.startDateStr = val
      } else {
        this.filterField.startDateStr = ''
      }
    },
    getEndTimeValue(val) {
      if (val) {
        this.filterField.endDateStr = val
      } else {
        this.filterField.endDateStr = ''
      }
    },
    download({ logFiles } = row) {
      logFiles && logFiles[0] && window.open(logFiles[0].url)
    },
    // 文件模式下拉
    getType() {
      this.axios({
        method: 'post',
        url: 'api-att/cs/macMachineLog/expand/getFileType',
      })
        .then((response) => {
          if (!response.data.hasError) {
            this.typeOptions = response.data.result
          } else {
            this.$message({
              message: response.data.errorMsg,
              type: 'error',
            })
          }
        })
        .catch((error) => {})
    },
    getTableList(data) {
      this.tableData = data
      this.loading = false
      if (this.tableData.length < 1) {
        this.isShow = true
      }
    },
    //列表查询
    searchTable() {
      this.$refs.pagination.getTableListData()
    },
  },
}
</script>

<style scoped lang="less">
@import '../../../static/css/filterArea.less';
.container {
  .selectWidth {
    width: 100%;
  }
}
</style>
